/*******************************************************************************
*   			Impacts of a Large-Scale Parenting Program: 				   *
*					Experimental Evidence from Chile						   *
********************************************************************************


	REQUIRES:	"${dt_final}panel_RR_indexes.dta"
	CREATES:	${out_tables}/T17A_attritionbaseline.xls
				
	WRITEN BY:  Italo Lopez  [italolop@usc.edu]

********************************************************************************
	Prepare data
*******************************************************************************/

	* Load data
	use "${dt_final}/panel_RR_indexes.dta", clear


	* Establish macros for regressions

/*******************************************************************************
*   Set macros for regressions
*******************************************************************************/
	
	* Outcomes
	*-----------------------------------------------------------
	local childoutcomes  "zDCCSPunt zptevir_irtscore2 zt_score zcbcl_t_e zcbcl_t_i zibatt_sspi zibatt_ssai zibatt_sssr zas_raw_score" 
	local behaviors "home_score se_score disc_score" 
	local beliefs "zpstyle1 zpstyle2 zpstyle3 zPSCS zPSSS_family zPSSS_friends zPSSS_others zPSI_Distress zCESD zpacotis"	
	local child "zptevir_irtscore2 zcog_index zsoc_index" 

	* Controls
	*-----------------------------------------------------------

	macro  def Xvar1 "i.age_year i.gender"  	
	macro  def Xvar2 "i.age_year i.gender inc_qtaut_old i.pc_edu_mdsfin hh_mem hh_tipo"  	
	macro  def Xvar2old "i.gender inc_qtaut_old i.pc_edu_mdsfin_old hh_mem hh_tipo"  

	
	* Parental characteristics: WAIS and BFI and imputed wais 
	*-----------------------------------------------------------

	macro def parent_cha4 "BFI_ext BFI_ope BFI_con BFI_neu BFI_agr wais2 flag_wais"
	

/*******************************************************************************
Table A17: Attrition: interaction with treatment arms and baseline variables
*******************************************************************************/

	//ta TIPO_old, g(tipoold)
	xi: xtreg attrite tipoold2 tipoold3, fe i(CENTRO_SALUD_old)
	estimates store attr_reg
	local attr "t_score_old dCCSPunt_old pepebdisoc_old Achenpunt_old pc_edu_old inc_qtaut_old"
	foreach var of local attr{
		gen `var'tipoold2=`var'*tipoold2
		gen `var'tipoold3=`var'*tipoold3
		xi: xtreg attrite tipoold2 tipoold3 `var' `var'tipoold2 `var'tipoold3, fe i(CENTRO_SALUD_old)
		estimates store attr_`var'
	}


esttab attr_reg attr_t_score_old attr_dCCSPunt_old attr_pepebdisoc_old /*
*/ attr_Achenpunt_old attr_pc_edu_old attr_inc_qtaut_old /*
*/ using "$out_tables/appendix/T17A_attritionbaseline.csv", replace f /*
*/ cells("b(fmt(3)star)" "se(fmt(3)par)") /*
*/ star(* 0.10 ** 0.05 *** 0.01) /*
*/ stats(r2  N mean_y, fmt(2  0 1) /*
*/ labels("R-squared"  "Observations" "Mean of dep. var.")) legend	/*
*/ varlabels(tipoold2 "NEP-B" tipoold3 "NEP-I" /*
*/ t_score_old "Treatment" t_score_oldtipoold2 "Treatment x NEP-B" t_score_oldtipoold3 "Treatment x NEP-I" /*
*/ dCCSPunt_old "Language" dCCSPunt_oldtipoold2 "Language x NEP-B" dCCSPunt_oldtipoold3 "Language x NEP-I" /*
*/ pepebdisoc_old "Socioemotional" pepebdisoc_oldtipoold2 "Socioemotional x NEP-B" pepebdisoc_oldtipoold3 "Socioemotional x NEP-I" /* 
*/ Achenpunt_old "Behaviour" Achenpunt_oldtipoold2 "Behaviour x NEP-B" Achenpunt_oldtipoold3 "Behaviour x NEP-I"/* 
*/ pc_edu_old "Education" pc_edu_oldtipoold2 "Education x NEP-B" pc_edu_oldtipoold3 "Education x NEP-I" /* 
*/ inc_qtaut_old "Income" inc_qtaut_oldtipoold2 "Income x NEP-B" inc_qtaut_oldtipoold3 "Income x NEP-I") /*
*/ mtitles("Treatment" "Language" "Executive Function" "Socioemotional" "Behaviour" "Education" "Income" ) 
							
	
